/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Object;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author PhongLK60473
 */
public class Page {
    public static void setLastSearch(String msg,HttpServletRequest request){
        request.getSession().setAttribute("LastSearch", msg);
        request.setAttribute("LastSearch", msg);
    }
    public static boolean isLastSearch(HttpServletRequest request){
        if(request.getSession().getAttribute("LastSearch")!=null){
            return true;
        } else if (request.getAttribute("LastSearch")!=null){
            return true;
        } else {
            return false;
        }
    }
    public static String getLastSearch(HttpServletRequest request){
        if(request.getSession().getAttribute("LastSearch")!=null){
            String msg = (String) request.getSession().getAttribute("LastSearch");
            //request.getSession().removeAttribute("LastSearch");
            //request.removeAttribute("LastSearch");
            return msg;
        } else if (request.getAttribute("LastSearch")!=null){
            String msg = (String) request.getAttribute("LastSearch");
            //request.removeAttribute("LastSearch");
            return msg;
        } else {
            return "";
        }
    }
    public static void setMessage(String msg,HttpServletRequest request){
        request.getSession().setAttribute("SessionMsg", msg);
    }
    public static boolean isMessage(HttpServletRequest request){
        return request.getSession().getAttribute("SessionMsg")!=null;
    }
    public static String getMessage(HttpServletRequest request){
        if(request.getSession().getAttribute("SessionMsg")!=null){
            String msg = (String) request.getSession().getAttribute("SessionMsg").toString();
            request.getSession().removeAttribute("SessionMsg");
            return msg;
        }
        return "";
    }
    public static void forward(String url,HttpServletRequest request,HttpServletResponse response){
        RequestDispatcher rd=request.getRequestDispatcher(url);
        try {
            rd.forward(request, response);
        } catch (IOException ioe){
            ioe.printStackTrace();
        } catch (ServletException se){
            se.printStackTrace();
        }
    }
    public static void include(String url,HttpServletRequest request,HttpServletResponse response){
        RequestDispatcher rd=request.getRequestDispatcher(url);
        try {
            rd.include(request, response);
        } catch (IOException ioe){
            ioe.printStackTrace();
        } catch (ServletException se){
            se.printStackTrace();
        }
    }
}
